﻿<?php

require_once 'teia.lib/inc/inc_core.inc';
use teia\webdev\php\core as teia;

require_once 'teia.cust/inc/inc_cust.inc';
use teia\webdev\php\cust as cust;

$result = teia\SessionWrapper::start();

if (!$result) {
	echo "Session Error: Failed to start session\n";
}
$err_msg = isset($_REQUEST['err_msg']) ? $_REQUEST['err_msg'] : '';

try {
	if (!isset($num_slides)) $num_slides = 5;
	//$filter = array('prod_gender' => 'F');
	$filter = null;
	if (isset($_REQUEST['prod_type']) && is_string($_REQUEST['prod_type'])) {
		//$filter['prod_type'] = $_REQUEST['prod_type'];;
	}
	// fetch products from database
	$product_listing = new teia\ProductCatalog('_product_catalog', 'ProductCatalog', null, $filter);
	$paginator = new teia\PaginationProvider('_pagination_', 'Pagination', null, $product_listing);
	$paginator->show_nav(false);
} catch (InvalidArgumentException $e) {
	$err_msg = $e->getMessage() . ' [' . $e->getCode() . ']';
} catch (Exception $e) {
	$err_msg = $e->getMessage() . ' [' . $e->getCode() . ']';
}
?>

<!DOCTYPE html>
<html>
	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
		<title>Shoes Boutique: Pagina Inicial</title>
		<link href="/style/catalog.css" rel="stylesheet" type="text/css">
		<link href="/style/layout.css" rel="stylesheet" type="text/css">
		<link href="/style/style01.css" rel="stylesheet" type="text/css">
		<link href="/style/style_slideshow.css" rel="stylesheet" type="text/css">
		<?php teia\FunctionPool::include_jquery(); ?>
		<style type="text/css">
			.auto-style1 {
				margin-left: 0;
			}
		</style>
		<script src="/script/jquery.min.js"></script>
		<script src="/script/script.js"></script>
		<script src="/script/autoadvance.js"></script>
	</head>
	<body>
		<div align="center" style="position: absolute; margin-left: inherit; margin-right: inherit">
			<!-- Display header logo -->
			<?php cust\CustFunctions::display_header_logo(); ?>
			<!-- Display top navigation -->
			<?php cust\CustFunctions::display_top_nav(); ?>
			<!-- Display menu -->	
			<?php cust\CustFunctions::display_menu(); ?>
			<div id="main_container">  
    			<?php cust\CustFunctions::display_top_banner(); ?>
				<div id="slideshow">
					<ul class="slides">
					<?php
						$all_slides = $product_listing->get_all_slides();
						$count = count($all_slides);
						$num_slides = ($num_slides <= $count) ? $num_slides : $count;
						$rand_keys = array_rand($all_slides, $num_slides); 
						foreach ($rand_keys as $key) {
							$slide = $all_slides[$key];
							echo "<li>$slide</li>\n";
						}
					?> 
					</ul>
					<span class="arrow previous"></span>
					<span class="arrow next"></span>
				</div>
	 			<div class="container" >
	 				<?php @$paginator->display('page'); ?>
	 			</div>
	 		</div>
	 		<?php cust\CustFunctions::display_footer();?>	
	 	</div>
	 </body>
</html>
